/**
 * 文件上传基础工具类
 */
package net.sapfree.fileUpload;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


/**
 * @author Administrator
 * 
 */
public class FileUploadManagerUtil
{
    
    /**
     * 拼装文件上传路径：根目录/年/月/日
     * 
     * @return
     */
    public static String getUploadPath()
    {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int date = calendar.get(Calendar.DATE);
        return year
            + File.separator
            + (month < 10 ? "0" + String.valueOf(month) : String
                .valueOf(month)) + File.separator
            + (date < 10 ? "0" + date : date + File.separator);
    }
    
    /**
     * 将文件名换成UUID
     * 
     * @param uuid
     * @param fileName
     * @return
     */
    public static String getNewFileName(String uuid, String fileName)
    {
        if ("".equals(fileName))
        {
            return uuid;
        }
        else
        {
            String[] tem = fileName.split("\\.");
            return uuid + "." + tem[tem.length - 1];
        }
        
    }
    
    /**
     * 获取时间
     * 
     * @return
     */
    public static String getCurrentDateTime()
    {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = df.format(new Date());
        return s;
    }
    
    /**
     * 
     * @param fileId
     * @return
     */
    public static String getDelFileById(String fileId)
    {
        return "DELETE AEG_DOCUMENT AD WHERE ID = '" + fileId + "'";
    }
    
}
